home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11526 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP. How to convert '0x12' into FF char?
  5. Date: Sun, 24 Mar 96 22:45:25 GMT
  6. Organization: none
  7. Message-ID: <827707525snz@genesis.demon.co.uk>
  8. References: <4iissm$s76@nntp.ucs.ubc.ca> <17MAR199623533662@erich.triumf.ca> <827344614snz@genesis.demon.co.uk> <AD76C75896683B250@mcdialb11.it.luc.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <AD76C75896683B250@mcdialb11.it.luc.edu>
  15.            VArase@varase.it.luc.edu "Verne Arase" writes:
  16.  
  17. >In article <827344614snz@genesis.demon.co.uk>,
  18. >Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
  19. >
  20. > >>>f='0x';
  21. > >>>strcpy(f,d);
  22. > >>>strcpy(f,e);
  23. > >>> 
  24. > >>>f now contains the string '0x12' right?
  25. > >>
  26. > >>No.
  27. > >
  28. > >Indeed, it isn't even legal code.
  29. >
  30. >Well, it's probably not legal (or at least suffers from suspicious pointer
  31. >conversion).
  32.  
  33. There is no conversion since a C compiler is not allowed to convert implicitly
  34. from an int to a pointer unless it is converting an integral constant
  35. expression with the value 0 (which becomes a null pointer of the target type).
  36. The code requires a diagnostic (if string.h was included) and the chances are
  37. that the compiler won't even generate an execuatble.
  38.  
  39. >What this would probably end up doing is copying characters until the first
  40. >NUL charcter is found from absolute memory location 0x00000032 (if ASCII)
  41. >or 0x000000F1 (if EBCDIC).
  42.  
  43. If there isn't an executable it can't even do that.
  44.  
  45. > >>but if you have:
  46. > >>        char f[10] = "0x";
  47. > >>        char d[2] = "1";
  48. > >>        char e[2] = "2";
  49. > >>        strcpy(f,d);
  50. > >>        strcpy(f,e);
  51. > >
  52. > >I assume you mean strcat() here.
  53. >
  54. >strcat(), like strcpy(), works with character _pointers.
  55.  
  56. Which are precisely what this code passes to it. But in order to build the
  57. string "0x12" you need to call strcat() instead of strcpy().
  58.  
  59. -- 
  60. -----------------------------------------
  61. Lawrence Kirby | fred@genesis.demon.co.uk
  62. Wilts, England | 70734.126@compuserve.com
  63. -----------------------------------------
  64.